﻿using DG.Tweening;
using System.Collections;
using UnityEngine;

namespace Miao.UI
{
    /// <summary>
    /// UI从水平一侧进入画面
    /// </summary>
    public class HorizontalEntryMotion : BaseUIMotion
    {
        float entryDistance;
        float duration;
        public Ease playEase = Ease.OutBack;
        public Ease backEase = Ease.InBack;
        public HorizontalEntryMotion(float entryDistance = 1920,float duration = 0.34f)
        {
            this.entryDistance = entryDistance;
            this.duration = duration;
        }

        public override void Play(bool forward, TweenCallback complete)
        {
            Tweener handle;
            if (forward)
            {
                TweenGameObject.transform.localPosition = new Vector3(entryDistance, 0, 0);
                handle = TweenGameObject.transform.DOLocalMoveX(0, duration);
                handle.SetEase(playEase);
            }
            else
            {
                handle = TweenGameObject.transform.DOLocalMoveX(entryDistance, duration);
                handle.SetEase(backEase);
            }
            handle.OnComplete(complete);
        }
    }
}